package com.bdqn.controller;

import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * SysUserController
 *
 * @author LILIBO
 * @since 2021-11-27
 */
@Controller
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @GetMapping("/hello/{id}")
    public Object hello(Model model, @PathVariable("id") Long id){
        SysUser sysUser = sysUserService.getById(id);
        model.addAttribute("user",sysUser);
        return "demo/hello";
    }

    @GetMapping("/inline")
    public String getString(Model model, HttpServletRequest request){
        System.out.println("进来了");
        model.addAttribute("userName","ling");
        request.setAttribute("test","request");
        request.getSession().setAttribute("test","session");
        model.addAttribute("date",new Date());
        return "demo/hello";
    }

    @GetMapping("/if")
    public String ifunless(Model model){
        model.addAttribute("flag","yes");
        return "demo/hello";
    }

    @GetMapping("/switchless")
    public String switchless(Model model){
        model.addAttribute("sex","woman");
        return "demo/hello";
    }

    @GetMapping("/list")
    public String list(Model model){//演示 for 循环
        List<SysUser> list = sysUserService.list();
        model.addAttribute("users",list);
        return "demo/hello";
    }

    @GetMapping("/index")
    public String index(){
        return "demo/index";
    }

    @GetMapping("/fragment")
    public String layout() {
        return "test";
    }

    @GetMapping("/test")
    public String main() {
        return "demo/test";
    }




    // @GetMapping("/test")
    // public Object test() {
    //     System.out.println("---------------------- /user/update ----------------------");
    //     SysUser sysUser = sysUserService.getById(4L);
    //     sysUser.setUsrName("小苍。。。");
    //     sysUserService.updateById(sysUser);
    //     return sysUser;
    // }
    //
    // @GetMapping("/list")
    // public Object getList() {
    //     System.out.println("---------------------- /user/list ----------------------");
    //     SysUser query = new SysUser();
    //     query.setUsrRoleId(4L);
    //     return sysUserService.getList(query);
    // }
}
